import {getDictList} from "@/api/system/dict/data";
import Vue from "vue";

class Dict {
  constructor(dict) {
    this.dict = dict;
  }

  async init(names) {
    await getDictList(names).then((response) =>{
      Vue.set(this.dict, "type", response.data);
    });
  }
}

const install = Vue => {
  Vue.mixin({
    data() {
      if (
        this.$options.dicts instanceof Array &&
        this.$options.dicts.length > 0
      ) {
        return { dict: {type:{}} };
      }
      return {};

    },
    created() {
      if (this.$options.dicts instanceof Array && this.$options.dicts.length>0) {
        new Dict(this.dict).init(this.$options.dicts);
      }
    },
  });
};

export default { install };
